<template>
  <div>
    <el-dialog title="查看定时任务" :visible.sync="open" width="80%" @close="close" center>
      <el-table v-loading="loading" :data="taskList" @selection-change="handleSelectionChange" stripe border>
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="采集商品id" align="center" prop="collectProductId"/>
        <el-table-column label="在线商品id" align="center" prop="sellerStoreProductId"/>
        <el-table-column label="速卖通商品id" align="center" prop="aeProductId"/>
        <el-table-column label="CN码" align="center" prop="storeUserName"/>
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.certificate_task_status" :value="scope.row.status"></dict-tag>
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remark">
          <template slot-scope="scope">
            <div>{{ scope.row.remark ? scope.row.remark : '暂无' }}</div>
          </template>
        </el-table-column>
        <el-table-column label="添加时间" align="center" prop="addTime" width="180"/>
        <el-table-column label="同步时间" align="center" prop="synchronizationTime" width="180">
          <template slot-scope="scope">
            <div>{{ scope.row.synchronizationTime ? scope.row.synchronizationTime : '暂无' }}</div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :pageSizes="[5, 10, 20]"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="close">确 定</el-button>
        <el-button @click="close">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getBrand} from "@/api/gather/collectProduct";
import {selectlistCollectProductCategory} from "@/api/gather/collectProductCategory";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {queryTimedTask} from "@/api/certificate/certificate"

export default {
  name: "GoodsList",
  dicts: ['certificate_task_status'],
  props: {
    programId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
      },
      taskList: []
    };
  },
  created() {
    this.getList()
  },
  methods: {
    // 关闭弹窗
    close() {
      this.$emit('close', false)
    },
    // 获取证书相关产品列表
    getList() {
      this.loading = true;
      queryTimedTask({programId: this.programId}).then(res => {
        this.taskList = res.rows;
        this.total = res.total;
        this.loading = false;
      })
    },
    // 商品类目
    getGoodsCategory() {
      selectlistCollectProductCategory().then(response => {
        this.categoryList = this.handleTree(response.data, "id", "parentId");
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 获取品牌选择列表
    getBrandList() {
      getBrand().then(res => {
        this.brandList = res.data
      });
    }
  }
};
</script>

<style lang="scss">

</style>

